package com.test.design_pattern.singleton;

public class Single03 {
    private static volatile Single03 INSTANCE;//语句重排

    private Single03() {
    }

    public static Single03 getInstance(){
        if (INSTANCE == null){
            //双重检查
            synchronized (Single03.class){
                if (INSTANCE == null){
                    INSTANCE = new Single03();
                }
            }
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i=0;i<100;i++){
            new Thread(()->{
                System.out.println(Single03.getInstance().hashCode());
            }).start();
        }
    }
}